<?php
namespace Admin\Controller;
use Think\Controller;
class IndexController extends CommonController {
    public function index(){
        $this->display();
    }
    public function listCate(){
        $catModel = M("Cat");
        $res = $catModel->order("sort asc")->select();
        $this->assign('res',$res);
        $this->display('cate');
    }
    public function addCate(){
        $data['pid'] = I('pid');
        $data['cat_name'] = I('cat_name');
        $data['seo_title'] = I('seo_title');
        $data['seo_keywords'] = I('seo_keywords');
        $data['seo_desc'] = I('seo_desc');
        $data['sort'] = I('sort');
        $catModel = M("Cat");
        //var_dump($data);exit;
        $rs = $catModel->add($data);
        if($rs){
            $this->success("添加成功",'',1);
        }else{
            $this->error("添加失败",'',1);
        }
    }
    public function delCate(){
        $catModel = M('Cat');
        $where['cat_id'] = I('cat_id');
        $res = $catModel->where($where)->delete();
        if($res){
            $rs['status'] = 200;
        }else{
            $rs['status'] = 0;
        }
        $this->ajaxReturn($rs);
    }
    public function editCate(){
        $catModel = M("Cat");
        $where['cat_id'] = I('cat_id');
        $res = $catModel->where($where)->find();
        $list = $catModel->getField('cat_id,cat_name');
        $this->assign('list',$list);
        $this->assign($res);
        $this->display('cateedit');
    }
    public function alterCate(){
        $data['pid'] = I('pid');
        $data['cat_name'] = I('cat_name');
        $data['seo_title'] = I('seo_title');
        $data['seo_keywords'] = I('seo_keywords');
        $data['seo_desc'] = I('seo_desc');
        $data['sort'] = I('sort');
        $where['cat_id'] = I('cat_id');
        $catModel = M("Cat");
        $rs = $catModel->where($where)->save($data);
        if($rs){
            $this->success("更新成功",'listcate',1);
        }else{
            $this->error("更新失败",'',1);
        }
    }
    public function test(){
    	$where['name'] = I('post.name');
    	$where['password'] = I('post.password');
    	$rs = M('User')->where($where)->find();
    	if($rs){
    		echo '登录成功';
    	}else{
    		$this->error('登录失败');;
    	}
    }
}